﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="AxisAlignedRectangleBruteForce.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2010, 2011
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.Collision.
//
//   starLiGHT.Collision is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Collision is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Collision. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Collision are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 3345                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-01-13 16:01:08 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Collision.BroadPhase
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Xna.Framework;
    using starLiGHT.Collections;
    #endregion

    public class AxisAlignedRectangleBruteForce : AbstractBroadPhase, IBroadPhase
    {
        public override bool Test(ICollidable2D a, ICollidable2D b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }

            if (b == null)
            {
                throw new ArgumentNullException("b");
            }

            return a.WorldBoundingRectangle.Intersects(b.WorldBoundingRectangle);
        }

        public override bool Test(ICollidable3D a, ICollidable3D b)
        {
            throw new NotSupportedException("AxisAlignedRectangleBruteForce is 2D only");
        }

        public override bool CheckCompatibility(ICollidable c)
        {
            try
            {
                if (c is ICollidable2D)
                {
                    return ((ICollidable2D)c).LocalBoundingRectangle != null;
                }
            }
            catch
            {
            }

            return false;
        }
    }
}
